package action;
import java.util.ArrayList;
import java.util.Map;


import models.*;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class commentAction extends ActionSupport{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String comment_box;
	private int issue_num;
	Map<String, Object> session;
	DeveloperData dev = new DeveloperData();
	
	
	
public String execute(){
	session = ActionContext.getContext().getSession();
	IssueData issue = (IssueData)session.get("Issue");
	System.out.println(issue.getIssue_num());
	
	DeveloperData developer = (DeveloperData)session.get("Developer");
	
	//System.out.println(developer.getDevelopername());
	System.out.println(comment_box);
	CommentData comment = new CommentData();
	comment.setComment(comment_box);
	String loggedin = (String)session.get("loggedin");
	if(loggedin.equalsIgnoreCase("admin"))
	{
		comment.setDeveloperName("Admin");
	}
	else{
	comment.setDeveloperName(developer.getDevelopername());}
	comment.setIssueId(issue.getIssue_id());
	
	comment.insert();

	
	Integer selected_issue_id= (Integer) session.get("selected_issue_id");
	
    ArrayList<CommentData> commentslist = new ArrayList<CommentData>();
	commentslist = CommentData.find(" where issue_id = " +selected_issue_id+";");
	int i;
	 for(i=0;i<commentslist.size();i++){}
	 //IssueData issue = new IssueData();
	 issue = IssueData.findOne(" where issue_id = " + selected_issue_id+";");
	 System.out.println("no. of comments "+i);
	session.put("comments",commentslist);
	session.put("Issue", issue);
	
	setComment_box("");
			return "success";
}
public String getComment_box() {
	return comment_box;
}
public void setComment_box(String comment_box) {
	this.comment_box = comment_box;
}
}
